#include"Stack.h"
void StackInit(STK* ps)//初始化
{
    assert(ps);
    ps->top=0;
    ps->a=NULL;
    ps->capacity=0;
}

void CheckCapacity(STK * ps)//增容
{
    if(ps->top==ps->capacity)
    {
        int NewCapacity=ps->capacity==0?4:ps->capacity*2;
        Value *ptr=(Value*)realloc(ps->a,sizeof(Value)*NewCapacity);
        if(ptr==NULL)
        {
            perror("ptr:");
        }

        ps->a=ptr;
        ps->capacity=NewCapacity;
    }
}
bool CheckEmpty(STK * ps)
{
   return ps->top==0;
}

void StackPush(STK * ps,Value Data)//压栈
{
    assert(ps);
    CheckCapacity(ps);//增容
    ps->a[ps->top]=Data;
    ps->top++;

}


void StackDestroy(STK * ps)//销毁
{
    assert(ps);
    free(ps->a);
    ps->a=NULL;
    ps->top=0;
    ps->capacity=0;
}

void StackPrint(STK * ps)//出栈
{
    --ps->top;
}

Value StackTop(STK* ps)//取栈顶
{
    return ps->a[ps->top];
}

Value StackSize(STK* ps)
{
    return ps->top;
}
